/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SitioDatosForm.java
 *
 * Created on 07/04/2010, 02:28:44 PM
 */

package agencia.form;

import agencia.LugarTuristico;
import agencia.TipoLugarTuristico;
import agencia.controller.LugarTuristicoController;
import agencia.controller.TipoLugarcontroller;
import javax.swing.JOptionPane;

/**
 *
 * @author elvis
 */
public class SitioDatosForm extends javax.swing.JInternalFrame {

    private TipoLugarcontroller tipoLugarcontroller;
    private LugarTuristicoController lugarTuristicoController;
    private SitioListaForm sitioListaForm;
    private LugarTuristico lugarTuristico;
    private int accion = 1;
    public static int ACCION_NUEVO = 1 ;
    public static int ACCION_MODIFICAR = 2 ;

    public void setTipoLugarcontroller(TipoLugarcontroller tipoLugarcontroller) {
        this.tipoLugarcontroller = tipoLugarcontroller;
    }
    public void setLugarTuristicoController(LugarTuristicoController lugarTuristicoController) {
        this.lugarTuristicoController = lugarTuristicoController;
    }
    public void setSitioListaForm(SitioListaForm sitioListaForm) {
        this.sitioListaForm = sitioListaForm;
    }
    public void setLugarTuristico(LugarTuristico lugarTuristico) {
        this.lugarTuristico = lugarTuristico;
    }
    public void setAccion(int accion) {
        this.accion = accion;
    }

    /** Creates new form SitioDatosForm */
    public SitioDatosForm() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        txtNombre = new javax.swing.JTextField();
        cbxTipoLugar = new javax.swing.JComboBox();
        btnGrabar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        setClosable(true);
        setTitle("Datos de Lugar Turistico");

        jLabel1.setText("Codigo");

        jLabel2.setText("Nombre");

        jLabel3.setText("Tipo Lugar");

        txtCodigo.setEnabled(false);

        cbxTipoLugar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btnGrabar.setText("Grabar");
        btnGrabar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGrabarActionPerformed(evt);
            }
        });

        btnCancelar.setText("Canclear");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtNombre)
                            .addComponent(cbxTipoLugar, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addComponent(btnGrabar)
                        .addGap(56, 56, 56)
                        .addComponent(btnCancelar)))
                .addContainerGap(41, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(cbxTipoLugar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnGrabar)
                    .addComponent(btnCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnGrabarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGrabarActionPerformed
        // TODO add your handling code here:
        if(accion==ACCION_NUEVO){
            lugarTuristicoController.nuevoLugarTuristico(txtNombre.getText(),cbxTipoLugar.getSelectedItem().toString() );
        }else{
            lugarTuristico.setNombre(txtNombre.getText());
            lugarTuristico.setTipoLugarTuristico( tipoLugarcontroller.obtenerTipoLugar( cbxTipoLugar.getSelectedItem().toString() ) );
        }
        JOptionPane.showMessageDialog(rootPane, "Datos modificados");
       sitioListaForm.pintagrilla( lugarTuristicoController.listaLugaresTuristicos(cbxTipoLugar.getSelectedItem().toString()) );
        this.dispose();
    }//GEN-LAST:event_btnGrabarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnGrabar;
    private javax.swing.JComboBox cbxTipoLugar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtNombre;
    // End of variables declaration//GEN-END:variables

   
    public void iniciaForm(){
        cbxTipoLugar.removeAllItems();
        for(TipoLugarTuristico tipo : tipoLugarcontroller.getListaTipoLugar()){
            cbxTipoLugar.addItem(tipo.getNombre());
        }
        if(accion==ACCION_NUEVO){
            lugarTuristico = new LugarTuristico();
        }else{
            txtCodigo.setText(lugarTuristico.getCodigo()+"");
            txtNombre.setText(lugarTuristico.getNombre());
            cbxTipoLugar.setSelectedItem(lugarTuristico.getTipoLugarTuristico().getNombre());
        }
    }

}
